package com.hrt.datasender.web.bcsendplatform;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.btcode.web.core.annotation.RequestMapping;
import com.btcode.web.core.controller.Controller;
import com.hrt.common.web.DSRequestUnit;
import com.hrt.datasender.datadao.model.BcSendPlatformModel;
import com.hrt.datasender.datadao.service.BcSendPlatformService;
import com.hrt.db.DBManager;

@RequestMapping(path = "BCSendPlatform")
public class BCSendPlatformController extends Controller {

    @RequestMapping(path = "getModel")
    public void getModel(ServletRequest arg0, ServletResponse arg1) throws IOException {
        String ip = DSRequestUnit.getParameter("IP");
        String port = DSRequestUnit.getParameter("PORT");
        BcSendPlatformModel model = BcSendPlatformService.getInstance().getPlatformInfo(ip, port);
        success(model);
    }

    @RequestMapping(path = "getModelList")
    public void getModelList(ServletRequest arg0, ServletResponse arg1) throws IOException {
        List<BcSendPlatformModel> list = BcSendPlatformService.getInstance().getModelList();
        success(list);
    }

    @RequestMapping(path = "saveModel")
    public void saveModel(ServletRequest arg0, ServletResponse arg1) throws IOException {
        BcSendPlatformModel model = DSRequestUnit.getModel(BcSendPlatformModel.class);
        BcSendPlatformService.getInstance().save(model);
        success(model);
    }

    @RequestMapping(path = "updateModel")
    public void updateModel(ServletRequest arg0, ServletResponse arg1) throws IOException {
        BcSendPlatformModel model = DSRequestUnit.getModel(BcSendPlatformModel.class);
        DBManager.getORMExecuter().update(model);
        success("");

    }

    @RequestMapping(path = "deleteModel")
    public void deleteModel(ServletRequest arg0, ServletResponse arg1) throws IOException {
        BcSendPlatformModel model = DSRequestUnit.getModel(BcSendPlatformModel.class);
        DBManager.getORMExecuter().delete(model);
        success("");

    }
}
